import urllib2
import socket
import cookielib

#timeout = 1 # seconds
#socket.setdefaulttimeout(timeout)


def get_original_url(url):
	#"""This function takes an url and returns the original url with cookie (if any)"""
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    usock = opener.open(url)
    url = usock.geturl()
    usock.close()
    return url, cj , opener
    


url,cj , opener = get_original_url('http://goo.gl/gjDeu') # write the url here
print url
usock = opener.open(url)

data = usock.read()
usock.close()

print data
